-
-
Notifications
You must be signed in to change notification settings - Fork 899
feat(claude-agent-sdk): add Claude Agent SDK as a provider #1947
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
feat(claude-agent-sdk): add Claude Agent SDK as a provider #1947
Conversation
Add support for the Claude Agent SDK as a new provider in instructor, enabling structured outputs with the SDK's native JSON schema validation. Key features: - New `from_claude_agent_sdk()` factory function - `CLAUDE_AGENT_SDK` mode for structured outputs - Automatic Pydantic model to JSON schema conversion - Async-only API leveraging the SDK's async generator pattern - Built-in retry support with error context - Message format conversion (instructor -> prompt) This allows users to leverage Claude Agent SDK's agentic capabilities while using instructor's familiar interface for structured outputs. Fixes 567-labs#1640
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Important
Looks good to me! 👍
Reviewed everything up to 49d9d6f in 1 minute and 7 seconds. Click for details.
- Reviewed
905lines of code in9files - Skipped
0files when reviewing. - Skipped posting
3draft comments. View those below. - Modify your settings and rules to customize what types of comments Ellipsis leaves. And don't forget to react with 👍 or 👎 to teach Ellipsis.
1. instructor/providers/claude_agent_sdk/client.py:147
- Draft comment:
When appending error context to the prompt for retries (lines 147-152), consider the potential for the prompt to grow significantly in length if many retries occur. It may be useful to implement a limit or log a warning if the prompt becomes too long. - Reason this comment was not posted:
Confidence changes required:80%<= threshold85%None
2. instructor/providers/claude_agent_sdk/client.py:140
- Draft comment:
The validated model has a dynamic attribute _raw_response attached. Make sure that the response model permits such attribute assignment (e.g. if using frozen models) or document this behavior for clarity. - Reason this comment was not posted:
Confidence changes required:70%<= threshold85%None
3. instructor/providers/claude_agent_sdk/client.py:110
- Draft comment:
The code uses actual_model.model_json_schema() for schema conversion. Ensure that the Pydantic model implements this method (pydantic v2) and document version requirements if supporting older versions. - Reason this comment was not posted:
Comment did not seem useful. Confidence is useful =30%<= threshold85%The comment is asking the author to ensure that a method is implemented and to document version requirements. This violates the rule against asking the author to ensure behavior or document version requirements. However, it does point out a potential issue with version compatibility, which could be useful if rephrased to suggest checking compatibility or updating documentation if necessary.
Workflow ID: wflow_eT8xfOXEW4LxgsHl
You can customize by changing your verbosity settings, reacting with 👍 or 👎, replying to comments, or adding code review rules.
Add synchronous interface alongside the async one. - New `use_async` parameter in `from_claude_agent_sdk()` (default: True) - `claude_agent_sdk_create_sync()` function using anyio.run() internally - Updated documentation with sync/async examples - Refactored code to share logic between sync and async implementations
Don't break early from the async generator - let it complete naturally to ensure proper cleanup of the subprocess transport.
|
Seems like the @ellipsis has not (yet) updated the description but it is no longer async-only now EDIT: now it has |
|
@jxnl Any chance to get a review on this? I'd love to integrate Claude Code SDK with Atomic Agents, which requires it to be integrated in Instructor. Perhaps a good future concept would be to make these clients more pluggable? |
Summary
Add support for the Claude Agent SDK as a new provider in instructor, enabling structured outputs with the SDK's native JSON schema validation capabilities.
Key Features
from_claude_agent_sdk()factory function - Creates an Instructor configured for Claude Agent SDKCLAUDE_AGENT_SDKmode - New mode for structured outputs via the SDKoutput_formatUsage Example
Files Added/Modified
New files:
instructor/providers/claude_agent_sdk/__init__.pyinstructor/providers/claude_agent_sdk/client.pyinstructor/providers/claude_agent_sdk/utils.pyexamples/claude_agent_sdk/run.pydocs/integrations/claude_agent_sdk.mdModified files:
instructor/__init__.py- Conditional import whenclaude_agent_sdkis availableinstructor/mode.py- AddedCLAUDE_AGENT_SDKmodeinstructor/utils/providers.py- AddedCLAUDE_AGENT_SDKproviderinstructor/processing/response.py- Added handler mappingsBenefits
Fixes #1640
Adds Claude Agent SDK as a new provider to the instructor framework, enabling structured outputs with JSON schema validation.
from_claude_agent_sdk()factory function inclient.pyto create anInstructorfor Claude Agent SDK.CLAUDE_AGENT_SDKmode inmode.pyfor structured outputs.instructor/providers/claude_agent_sdk/__init__.py,client.py, andutils.pyfor Claude Agent SDK integration.instructor/__init__.pyfor conditional import offrom_claude_agent_sdk.instructor/processing/response.pyto include handler mappings for Claude Agent SDK.docs/integrations/claude_agent_sdk.mdfor integration guide.examples/claude_agent_sdk/run.pyfor usage examples.CLAUDE_AGENT_SDKtoProviderenum inproviders.py.This description was created by
for 49d9d6f. You can customize this summary. It will automatically update as commits are pushed.